package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.StatusType;
import com.ef.dao.TeamDao;
import com.ef.domain.Team;
import com.ef.service.TeamService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class TeamServiceImpl extends BaseServiceImpl implements TeamService {

	private TeamDao teamDao;

	public void delete(Team entity) {
		entity.setStatus(StatusType.INVALID);
		teamDao.update(entity);
	}

	public PaginationSupport<Team> findByExample(CustomExample<Team> example,
			int startIndex, int pageSize) {
		return teamDao.findPageByExample(example, startIndex, pageSize);
	}

	public Team findById(Long id) {
		return teamDao.findById(id);
	}

	public void saveOrUpdate(Team entity) {
		teamDao.saveOrUpdate(entity);
	}

	public List<Team> findAll() {
		DetachedCriteria criteria = DetachedCriteria.forClass(Team.class);
		criteria.add(Restrictions.eq("status", StatusType.VALID));
		return teamDao.findAllByCriteria(criteria);
	}

	public List<Team> findByName(String name) {

		return teamDao.findByName(name);
	}

	public TeamDao getTeamDao() {
		return teamDao;
	}

	public void setTeamDao(TeamDao teamDao) {
		this.teamDao = teamDao;
	}

}
